package ${ControllerPackageName};

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pattern.exception.PatternException;
import pattern.annontations.Menu;
import pattern.annontations.Secure;
import ${EntityPackageName};
import pattern.cache.InitCache;
import pattern.result.ResponseData;
import pattern.result.ResponsePage;
import pattern.exception.AssertTool;

import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @author ${Author}
 * @date ${Date}
 */
@Api(tags = "${modelName}")
@RestController
@RequestMapping(value = "/api/")
@Menu(menuName = "${className}", menuUri = "${className}", foundational = false)
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Secure
@Slf4j
public class ${className}Controller {

    @ApiOperation(value = "查询")
    @ApiOperationSupport(order = 1)
    @PostMapping("search")
    @Secure(actionUri = "${className}:search", actionName = "search", actionNote = "${className}")
    public ResponsePage<${className}> search(@RequestBody ${className}ResponseModel model) {
        return WorkServiceTool.get${className}Service().pageResponse(model, ${className}Response.class);
    }


    @ApiOperation(value = "详情")
    @GetMapping("/{id}")
    @ApiOperationSupport(order = 2)
    @Secure(actionUri = "${className}:search")
    public ResponseData<${className}> detail(@PathVariable Integer id) {
        return new ResponseData<>(*ServiceTool.get${className}Service().getById(new BaseIdModel<>(id)));
    }

    @ApiOperation(value = "新增")
    @ApiOperationSupport(order = 3)
    @PostMapping
    @Secure(actionUri = "${LowerEntityName}:add", actionName = "add", actionNote = "${className}")
    public ResponseData<Boolean> add${className}(@Valid @RequestBody ${className}AddOrUpdateModel model){
         var flag = Objects.nonNull(*ServiceTool.get${className}Service().saveOrUpdate(model));
         return new ResponseData<>(flag);
    }

    @ApiOperation(value = "修改")
    @ApiOperationSupport(order = 4)
    @PutMapping
    @Secure(actionUri = "${LowerEntityName}:update", actionName = "update", actionNote = "${className}")
    public ResponseData<Boolean> update${className}(@Valid @RequestBody ${className}AddOrUpdateModel model){
         var flag = Objects.nonNull(*ServiceTool.get${className}Service().saveOrUpdate(model));
         return new ResponseData<>(flag);
    }

    @ApiOperation(value = "删除")
    @ApiOperationSupport(order = 5)
    @DeleteMapping("/{id}")
    @Secure(value = 1, actionUri = "${LowerEntityName}:del", actionName = "delete", actionNote = "${className}")
    @ApiOperationSupport(order = 4)
    public ResponseData<Boolean> delete(@PathVariable Integer[] id) {
         return new ResponseData<>(*ServiceTool.get${className}Service().removeByIds(new BaseIdModel<>(List.of(id))));
    }

}